﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Colletswith8settinganglefortoolshanks
    {
        public static void _Colletswith8settinganglefortoolshanks(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 1; //放大系数

            double d1 = 1;
            double d2 = 11;
            double d3 = 11.3;
            double d4 = 5;
            double d5 = 9.5;
            double d6 = 11.6;
            double l1 = 18;
            double l2 = 2;
            double l3 = 2;
            double l4 = 2.5;
            double l5 = 9;

            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + l1 + 6, v1.Y);
            Vector2 v3 = new Vector2(v2.X - 3, v2.Y);
            Vector2 v6 = new Vector2(v3.X - l4, v3.Y + d6 / 2);
            Vector2 v5 = new Vector2(v6.X + l4 / 6.574, v3.Y + d3 / 2);
            Vector2 v4 = new Vector2(v3.X, v5.Y - (v3.X - v5.X) * Math.Tan(30 * pi / 180));
            Vector2 v7 = new Vector2(v6.X, v3.Y + d5 / 2);
            Vector2 v8 = new Vector2(v7.X - l3, v7.Y);
            Vector2 v10 = new Vector2(v8.X - l2 + l3, v3.Y + d2 / 2);
            Vector2 v9 = new Vector2(v8.X, v10.Y + (l2 - l3) * Math.Tan(8 * pi / 180));
            Vector2 v11 = new Vector2(v1.X + 3, v10.Y - (l1 - l2 - l4) * Math.Tan(8 * pi / 180));
            Vector2 v12 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v13 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v14 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v15 = new Vector2(v7.X, v7.Y * -1);
            Vector2 v16 = new Vector2(v8.X, v8.Y * -1);
            Vector2 v17 = new Vector2(v9.X, v9.Y * -1);
            Vector2 v18 = new Vector2(v10.X, v10.Y * -1);
            Vector2 v19 = new Vector2(v11.X, v11.Y * -1);
            Vector2 v20 = new Vector2(v4.X, v4.Y - (v6.Y - v7.Y));
            Vector2 v21 = new Vector2(v5.X, v7.Y);
            Vector2 v22 = new Vector2(v20.X, v20.Y - d6 / 44.5333);
            Vector2 v23 = new Vector2(v21.X, v21.Y - d6 / 44.5333);
            Vector2 v24 = new Vector2(v7.X, v23.Y);
            Vector2 v25 = new Vector2(v8.X, v8.Y + d6 / 44.5333);
            Vector2 v27 = new Vector2(v11.X, v11.Y - (v9.Y - v8.Y));
            Vector2 v26 = new Vector2(v27.X, v27.Y + d6 / 44.5333);
            Vector2 v28 = new Vector2(v20.X, v20.Y * -1);
            Vector2 v29 = new Vector2(v21.X, v21.Y * -1);
            Vector2 v30 = new Vector2(v22.X, v22.Y * -1);
            Vector2 v31 = new Vector2(v23.X, v23.Y * -1);
            Vector2 v32 = new Vector2(v25.X, v25.Y * -1);
            Vector2 v33 = new Vector2(v26.X, v26.Y * -1);
            Vector2 v34 = new Vector2(v27.X, v27.Y * -1);
            Vector2 v35 = new Vector2(v3.X, v3.Y + d6 / 6.322);
            Vector2 v36 = new Vector2(v35.X - l4 / 2.942, v35.Y);
            Vector2 v37 = fun.Polar(v36, -110 * pi / 180, d6 / 10.891);
            Vector2 v38 = fun.Polar(v37, -94 * pi / 180, d6 / 45.545);
            Vector2 v39 = fun.Polar(v38, -91 * pi / 180, d6 / 28.225);
            Vector2 v40 = fun.Polar(v39, -76 * pi / 180, d6 / 31.81);
            Vector2 v41 = fun.Polar(v40, -68 * pi / 180, d6 / 27.081);
            Vector2 v42 = fun.Polar(v41, -99 * pi / 180, d6 / 30.364);
            Vector2 v44 = new Vector2(v3.X, v3.Y - d6 / 5.949);
            Vector2 v43 = new Vector2(v36.X, v44.Y);
            Vector2 v45 = new Vector2(v23.X, v39.Y);
            Vector2 v46 = new Vector2(v24.X, v45.Y);
            Vector2 v47 = new Vector2(v8.X, v46.Y);
            Vector2 v48 = new Vector2(v11.X, v47.Y);
            Vector2 v49 = new Vector2(v45.X, v40.Y);
            Vector2 v50 = new Vector2(v46.X, v49.Y);
            Vector2 v51 = new Vector2(v47.X, v50.Y);
            Vector2 v52 = new Vector2(v48.X, v51.Y);
            Vector2 v53 = new Vector2(v35.X, v37.Y);
            Vector2 v54 = new Vector2(v35.X, v38.Y);
            Vector2 v55 = new Vector2(v35.X, v41.Y);
            Vector2 v56 = new Vector2(v35.X, v42.Y);
            Vector2 v57 = new Vector2(v7.X, v7.Y - d6 / 20.66);
            Vector2 v58 = new Vector2(v8.X, v57.Y);
            Vector2 v59 = new Vector2(v57.X, v57.Y - d6 / 44.5333);
            Vector2 v60 = new Vector2(v58.X, v59.Y);
            Vector2 v61 = new Vector2(v57.X, v57.Y * -1);
            Vector2 v62 = new Vector2(v58.X, v58.Y * -1);
            Vector2 v63 = new Vector2(v59.X, v59.Y * -1);
            Vector2 v64 = new Vector2(v60.X, v60.Y * -1);
            Vector2 v65 = new Vector2(v7.X, v7.Y - d6 / 6.204);
            Vector2 v66 = new Vector2(v23.X, v65.Y);
            Vector2 v67 = new Vector2(v4.X, v4.Y - d6 / 5.98);
            Vector2 v68 = new Vector2(v4.X, v67.Y - d6 / 32.322);
            Vector2 v69 = new Vector2(v5.X, v66.Y - (v67.Y - v68.Y));
            Vector2 v70 = new Vector2(v7.X, v69.Y);
            Vector2 v71 = new Vector2(v8.X, v70.Y);
            Vector2 v72 = fun.Polar(v71, -176 * pi / 180, (l1 - l3 - l4) / 1.036);
            Vector2 v74 = new Vector2(v71.X, v65.Y);
            Vector2 v73 = new Vector2(v72.X, v72.Y + (v74.Y - v71.Y));
            Vector2 v75 = new Vector2(v65.X, v65.Y * -1);
            Vector2 v76 = new Vector2(v66.X, v66.Y * -1);
            Vector2 v77 = new Vector2(v67.X, v67.Y * -1);
            Vector2 v78 = new Vector2(v68.X, v68.Y * -1);
            Vector2 v79 = new Vector2(v69.X, v69.Y * -1);
            Vector2 v80 = new Vector2(v70.X, v70.Y * -1);
            Vector2 v81 = new Vector2(v71.X, v71.Y * -1);
            Vector2 v82 = new Vector2(v72.X, v72.Y * -1);
            Vector2 v83 = new Vector2(v73.X, v73.Y * -1);
            Vector2 v84 = new Vector2(v74.X, v74.Y * -1);
            Vector2 v85 = new Vector2(v71.X, v71.Y - d6 / 32.322);
            Vector2 v86 = new Vector2(v70.X, v85.Y);
            Vector2 v87 = new Vector2(v85.X, v85.Y * -1);
            Vector2 v88 = new Vector2(v86.X, v86.Y * -1);
            Vector2 v89 = new Vector2(v3.X, v3.Y + d1 / 2);
            Vector2 v90 = new Vector2(v89.X - (l1 - l5) / 1.086, v89.Y);
            Vector2 v91 = new Vector2(v11.X + l5, v74.Y - (l1 - l3 - l4 - l5) * Math.Tan(4 * pi / 180));
            Vector2 v92 = new Vector2(v89.X, v89.Y * -1);
            Vector2 v93 = new Vector2(v90.X, v90.Y * -1);
            Vector2 v94 = new Vector2(v91.X, v91.Y * -1);




            //作图
            Line line1 = new Line(v1 , v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v46));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v21));
            fun.PolyFill(dxf, line2, 0.05, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v5));
            line3.Vertexes.Add(new LwPolylineVertex(v4));
            line3.Vertexes.Add(new LwPolylineVertex(v12));
            line3.Vertexes.Add(new LwPolylineVertex(v13));
            fun.PolyFill(dxf, line3, 0.05, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v50));
            line4.Vertexes.Add(new LwPolylineVertex(v14));
            line4.Vertexes.Add(new LwPolylineVertex(v13));
            line4.Vertexes.Add(new LwPolylineVertex(v29));
            fun.PolyFill(dxf, line4, 0.05, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v47));
            line5.Vertexes.Add(new LwPolylineVertex(v9));
            line5.Vertexes.Add(new LwPolylineVertex(v10));
            line5.Vertexes.Add(new LwPolylineVertex(v11));
            line5.Vertexes.Add(new LwPolylineVertex(v19));
            line5.Vertexes.Add(new LwPolylineVertex(v18));
            line5.Vertexes.Add(new LwPolylineVertex(v17));
            line5.Vertexes.Add(new LwPolylineVertex(v51));
            fun.PolyFill(dxf, line5, 0.05, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v7));
            line6.Vertexes.Add(new LwPolylineVertex(v21));
            line6.Vertexes.Add(new LwPolylineVertex(v20));
            line6.Vertexes.Add(new LwPolylineVertex(v22));
            line6.Vertexes.Add(new LwPolylineVertex(v23));
            line6.Vertexes.Add(new LwPolylineVertex(v24));
            line6.Vertexes.Add(new LwPolylineVertex(v23));
            line6.Vertexes.Add(new LwPolylineVertex(v45));
            fun.PolyFill(dxf, line6, 0.05, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v7));
            line7.Vertexes.Add(new LwPolylineVertex(v8));
            line7.Vertexes.Add(new LwPolylineVertex(v27));
            line7.Vertexes.Add(new LwPolylineVertex(v26));
            line7.Vertexes.Add(new LwPolylineVertex(v25));
            fun.PolyFill(dxf, line7, 0.05, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v30));
            line8.Vertexes.Add(new LwPolylineVertex(v31));
            line8.Vertexes.Add(new LwPolylineVertex(v49));
            fun.PolyFill(dxf, line8, 0.05, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v28));
            line9.Vertexes.Add(new LwPolylineVertex(v29));
            line9.Vertexes.Add(new LwPolylineVertex(v15));
            line9.Vertexes.Add(new LwPolylineVertex(v16));
            line9.Vertexes.Add(new LwPolylineVertex(v34));
            line9.Vertexes.Add(new LwPolylineVertex(v33));
            line9.Vertexes.Add(new LwPolylineVertex(v32));
            fun.PolyFill(dxf, line9, 0.05, contour);

            LwPolyline line10 = new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v39));
            line10.Vertexes.Add(new LwPolylineVertex(v48));
            line10.Vertexes.Add(new LwPolylineVertex(v52));
            line10.Vertexes.Add(new LwPolylineVertex(v40));
            fun.PolyFill(dxf, line10, 0.05, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v42));
            line11.Vertexes.Add(new LwPolylineVertex(v43));
            line11.Vertexes.Add(new LwPolylineVertex(v44));
            line11.Vertexes.Add(new LwPolylineVertex(v35));
            line11.Vertexes.Add(new LwPolylineVertex(v36));
            line11.Vertexes[0].Bulge = Math.Tan(82 * pi / 180 / 4);
            fun.PolyFill(dxf, line11, 0.05, contour);

            Arc c1 = fun.DrawArc3(v36, v37, v38);
            fun.drawBArc(dxf, c1, 0.05, contour);

            Arc c2 = fun.DrawArc3(v38, v39, v40);
            fun.drawBArc(dxf, c2, 0.05, contour);

            Arc c3 = fun.DrawArc3(v42, v41, v40);
            fun.drawBArc(dxf, c3, 0.05, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v37));
            line12.Vertexes.Add(new LwPolylineVertex(v53));
            line12.Vertexes.Add(new LwPolylineVertex(v54));
            line12.Vertexes.Add(new LwPolylineVertex(v38));
            fun.PolyFill(dxf, line12, 0.05, contour);

            LwPolyline line13 = new LwPolyline();
            line13.Vertexes.Add(new LwPolylineVertex(v41));
            line13.Vertexes.Add(new LwPolylineVertex(v55));
            line13.Vertexes.Add(new LwPolylineVertex(v56));
            line13.Vertexes.Add(new LwPolylineVertex(v42));
            fun.PolyFill(dxf, line13, 0.05, contour);

            LwPolyline line14 = new LwPolyline();
            line14.Vertexes.Add(new LwPolylineVertex(v57));
            line14.Vertexes.Add(new LwPolylineVertex(v58));
            line14.Vertexes.Add(new LwPolylineVertex(v60));
            line14.Vertexes.Add(new LwPolylineVertex(v59));
            fun.PolyFill(dxf, line14, 0.05, contour);

            LwPolyline line15 = new LwPolyline();
            line15.Vertexes.Add(new LwPolylineVertex(v61));
            line15.Vertexes.Add(new LwPolylineVertex(v62));
            line15.Vertexes.Add(new LwPolylineVertex(v64));
            line15.Vertexes.Add(new LwPolylineVertex(v63));
            fun.PolyFill(dxf, line15, 0.05, contour);

            LwPolyline line16 = new LwPolyline();
            line16.Vertexes.Add(new LwPolylineVertex(v65));
            line16.Vertexes.Add(new LwPolylineVertex(v66));
            line16.Vertexes.Add(new LwPolylineVertex(v67));
            line16.Vertexes.Add(new LwPolylineVertex(v68));
            line16.Vertexes.Add(new LwPolylineVertex(v69));
            line16.Vertexes.Add(new LwPolylineVertex(v70));
            line16.Vertexes.Add(new LwPolylineVertex(v71));
            line16.Vertexes.Add(new LwPolylineVertex(v72));
            line16.Vertexes.Add(new LwPolylineVertex(v73));
            line16.Vertexes.Add(new LwPolylineVertex(v74));
            fun.PolyFill(dxf, line16, 0.05, contour);

            LwPolyline line17 = new LwPolyline();
            line17.Vertexes.Add(new LwPolylineVertex(v75));
            line17.Vertexes.Add(new LwPolylineVertex(v76));
            line17.Vertexes.Add(new LwPolylineVertex(v77));
            line17.Vertexes.Add(new LwPolylineVertex(v78));
            line17.Vertexes.Add(new LwPolylineVertex(v79));
            line17.Vertexes.Add(new LwPolylineVertex(v80));
            line17.Vertexes.Add(new LwPolylineVertex(v81));
            line17.Vertexes.Add(new LwPolylineVertex(v82));
            line17.Vertexes.Add(new LwPolylineVertex(v83));
            line17.Vertexes.Add(new LwPolylineVertex(v84));
            fun.PolyFill(dxf, line17, 0.05, contour);

            LwPolyline line18 = new LwPolyline();
            line18.Vertexes.Add(new LwPolylineVertex(v85));
            line18.Vertexes.Add(new LwPolylineVertex(v86));
            fun.PolyFill(dxf, line18, 0.05, contour);

            LwPolyline line19 = new LwPolyline();
            line19.Vertexes.Add(new LwPolylineVertex(v87));
            line19.Vertexes.Add(new LwPolylineVertex(v88));
            fun.PolyFill(dxf, line19, 0.05, contour);

            Line line20 = new Line(v89, v90);
            line20.Layer = refin;
            line20.Linetype = Linetype.Dashed;
            line20.LinetypeScale = 3;
            dxf.AddEntity(line20);

            Line line21 = new Line(v90, v91);
            line21.Layer = refin;
            line21.Linetype = Linetype.Dashed;
            line21.LinetypeScale = 5;
            dxf.AddEntity(line21);

            Line line22 = new Line(v91, v94);
            line22.Layer = refin;
            line22.Linetype = Linetype.Dashed;
            line22.LinetypeScale = 5;
            dxf.AddEntity(line22);

            Line line23 = new Line(v94, v93);
            line23.Layer = refin;
            line23.Linetype = Linetype.Dashed;
            line23.LinetypeScale = 5;
            dxf.AddEntity(line23);

            Line line24 = new Line(v93, v90);
            line24.Layer = refin;
            line24.Linetype = Linetype.Dashed;
            line24.LinetypeScale = 5;
            dxf.AddEntity(line24);

            Line line25 = new Line(v93, v92);
            line25.Layer = refin;
            line25.Linetype = Linetype.Dashed;
            line25.LinetypeScale = 5;
            dxf.AddEntity(line25);



            //标注

            double height = 2;
            double arrowsize = 1;
            double exline = 2;




            fun.dimrot1(dxf, v6, v14, -90, l1, 1, height, arrowsize, exline, "d6=" + d6, "", "");

            fun.dimrot1(dxf, v5, v13, -90, l1 - l2 - l4, 1, height, arrowsize, exline, "d3=" + d3, "", "");

            fun.dimrot1(dxf, v7, v15, -90, l1 / 2, 1, height, arrowsize, exline, "d5=" + d5, "", "");

            fun.dimrot1(dxf, v89, v92, -90, l5 / 2, 1, height, arrowsize, exline, "d1=" + d1, "", "");

            fun.dimrot1(dxf, v19, v94, 180, l1 / 2, 1, height, arrowsize, exline, "l5=" + l5, "", "");
            
            fun.dimrot1(dxf, v12, v14, 180, l2 * 2, 1, height, arrowsize, exline, "l4=" + l4, "", "");

            fun.dimrot1(dxf, v12, v19, 180, l1, 1, height, arrowsize, exline, "l1=" + l1, "", "");

            fun.jdbz2(dxf, new Line(v9, fun.Polar(v9, 180 * pi / 180, 0.1)), new Line(v9, fun.Polar(v9, -172 * pi / 180, 0.1)), l1, height, arrowsize, exline, "8°", "", "");

            fun.gcbz(dxf, (fun.Polar(v13, 30 * pi / 180, l4 / 2)), l4 * 2, -60, 7, 0, 8, 1, 1, "A", "0.005", 2, "ytd", 1);





            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}
